package org.example.Demo;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

public class JDBCDemo_Druid {
    public static void main(String[] args) throws Exception {

        //加载配置文件
        Properties prop = new Properties();
        prop.load(new FileInputStream("D:\\JavaCode\\JDBC_Demo1\\jdbcDemo\\druid.properties"));

        //获取连接池对象
        DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
        Connection conn = dataSource.getConnection();


        int id = 2;
        String name = "李四";

        String sql = "select * from account where id = ? and name = ?";
        PreparedStatement prstm = conn.prepareStatement(sql);
        prstm.setInt(1,id);
        prstm.setString(2,name);
        ResultSet res = prstm.executeQuery();

        if (res.next()){
            System.out.println("登录成功!!!");
        }else {
            System.out.println("登录失败!!!");
        }

        //释放资源
        conn.close();
        prstm.close();
        res.close();

    }
}
